package chat.clients.fb;

import chat.clients.XmppClient;
import chat.clients.fb.helper.CustomSASLDigestMD5Mechanism;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;

public class FBClient extends XmppClient {

    public static final String FB_XMPP_HOST = "chat.facebook.com";
    public static final int FB_XMPP_PORT = 5222;
    public static final String DIGEST_MD5 = "DIGEST-MD5";
    public static final FBClient INSTANCE = new FBClient();

    private FBClient() {
    }

    @Override
    public String connect() throws XMPPException {
        setState(CONNECTING);
        ConnectionConfiguration config = new ConnectionConfiguration(FB_XMPP_HOST, FB_XMPP_PORT);
        SASLAuthentication.registerSASLMechanism(DIGEST_MD5
                , CustomSASLDigestMD5Mechanism.class);
        config.setSASLAuthenticationEnabled(true);
        config.setDebuggerEnabled(false);
        connection = new XMPPConnection(config);
        connection.connect();

        return connection.getConnectionID();
    }

}